/**************************************************************************************************
* Title: SumInputManager.cpp
* Author: Gael Huber
* Description: Manager for all game input. Manages polling for input as well as updating input
*	values.
**************************************************************************************************/
#include "SumInputManager.h"

/**************************************************************************************************
* Initialize the singleton instance of this class to 0
**************************************************************************************************/
template <> InputManager* Singleton<InputManager>::singleton = 0;

/**************************************************************************************************
* Constructor
**************************************************************************************************/
InputManager::InputManager(void)
	: inputDevice(0), keyboard(0)
{ }

/**************************************************************************************************
* Destructor
**************************************************************************************************/
InputManager::~InputManager(void)
{ }

/**************************************************************************************************
* Input manager start-up function
**************************************************************************************************/
void InputManager::startUp(void) {
	// Create the DirectInput device
	DirectInput8Create(	GetHInstance(),		// The application handle
						DIRECTINPUT_VERSION,	// The current DirectInput version
						IID_IDirectInput8,		// DirectInput interface version
						(void**)&inputDevice,	// DirectInput interface pointer
						NULL);

	// Create the keyboard
	keyboard = new Keyboard(inputDevice);

	// Create the mouse
	mouse = new Mouse(inputDevice);
}

/**************************************************************************************************
* Input manager shut down function
**************************************************************************************************/
void InputManager::shutDown(void) {
	if(keyboard)	delete keyboard;

	// Free the input device
	if(inputDevice) inputDevice->Release();
}

/**************************************************************************************************
* Poll for input across hardware devices
**************************************************************************************************/
void InputManager::kickPollInput(void* p) {
	static_cast<InputManager*>(p)->pollInput();
}

/**************************************************************************************************
* Poll for input
**************************************************************************************************/
void InputManager::pollInput(void) {
	// Update the keyboard
	keyboard->update();

	// Update the mouse
	mouse->update();
}